<!DOCTYPE html>
<html  lang="en">
<head>
    <meta charset="utf-8">
<title>DRF框架 - noback</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />



    <meta name="description" content="rust风格Representational State Transfer  表现层状态转化（ 资源定位及资源操作）表象层面说就是通过get,post,put,delete方式来实现前后台通信的一种轻量级,跨平台,跨语言架构设计风格的web服务 http不仅仅是传输协议，更是一种应用协议。REST，即Representational State Transfer的缩写。意为是”表现层状态转化”。R">
<meta property="og:type" content="article">
<meta property="og:title" content="DRF框架">
<meta property="og:url" content="http://alpaca-h.gitee.io/2019/12/29/blog_back_new/django/drf%E6%A1%86%E6%9E%B6/drf%E6%A1%86%E6%9E%B6/index.html">
<meta property="og:site_name" content="noback">
<meta property="og:description" content="rust风格Representational State Transfer  表现层状态转化（ 资源定位及资源操作）表象层面说就是通过get,post,put,delete方式来实现前后台通信的一种轻量级,跨平台,跨语言架构设计风格的web服务 http不仅仅是传输协议，更是一种应用协议。REST，即Representational State Transfer的缩写。意为是”表现层状态转化”。R">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="http://alpaca-h.gitee.io/images/og_image.png">
<meta property="article:published_time" content="2019-12-29T12:42:23.000Z">
<meta property="article:modified_time" content="2019-12-29T12:56:13.071Z">
<meta property="article:author" content="Alpaca">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://alpaca-h.gitee.io/images/og_image.png">







<link rel="icon" href="/images/favicon.svg">


<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.7.2/css/bulma.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.1/css/all.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Ubuntu:400,600|Source+Code+Pro">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@9.12.0/styles/androidstudio.css">


    
    
    
    <style>body>.footer,body>.navbar,body>.section{opacity:0}</style>
    

    
    
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/lightgallery@1.6.8/dist/css/lightgallery.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/css/justifiedGallery.min.css">
    

    
    

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/outdatedbrowser@1.1.5/outdatedbrowser/outdatedbrowser.min.css">


    
    
    
    

<link rel="stylesheet" href="/css/back-to-top.css">


    
    

    
    
    
    

    
    
<link rel="stylesheet" href="/css/progressbar.css">
<script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>

    
    
    

    
    
    
        <script async="" src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    

    


<link rel="stylesheet" href="/css/style.css">
<meta name="generator" content="Hexo 4.2.0"><link rel="alternate" href="/atom.xml" title="noback" type="application/atom+xml">
</head>
<body class="is-3-column">
    <nav class="navbar navbar-main">
    <div class="container">
        <div class="navbar-brand is-flex-center">
            <a class="navbar-item navbar-logo" href="/">
            
                <img src="/images/logo.svg" alt="DRF框架" height="28">
            
            </a>
        </div>
        <div class="navbar-menu">
            
            <div class="navbar-start">
                
                <a class="navbar-item"
                href="/">Home</a>
                
                <a class="navbar-item"
                href="/archives/">Archives</a>
                
                <a class="navbar-item"
                href="/categories/">Categories</a>
                
                <a class="navbar-item"
                href="/tags/">Tags</a>
                
                <a class="navbar-item"
                href="/about/">About</a>
                
            </div>
            
            <div class="navbar-end">
                
                    
                    
                    <a class="navbar-item" target="_blank" title="AlphaLxy GitHub" href="https://www.github.com/AlphaLxy">
                        
                        <i class="fab fa-github"></i>
                        
                    </a>
                    
                
                
                <a class="navbar-item is-hidden-tablet catalogue" title="Catalogue" href="javascript:;">
                    <i class="fas fa-list-ul"></i>
                </a>
                
                
                <a class="navbar-item search" title="Search" href="javascript:;">
                    <i class="fas fa-search"></i>
                </a>
                
            </div>
        </div>
    </div>
</nav>
    
    <section class="section">
        <div class="container">
            <div class="columns">
                <div class="column is-8-tablet is-8-desktop is-9-widescreen has-order-2 column-main"><div class="card">
    
    <div class="card-content article ">
        <h1 class="title is-size-3 is-size-4-mobile has-text-weight-normal">
            
                <i class="fas fa-angle-double-right"></i>DRF框架
            
        </h1>
        
        <div class="level article-meta is-size-7 is-uppercase is-mobile is-overflow-x-auto">
            <div class="level-left">
                <time class="level-item has-text-grey" datetime="2019-12-29T12:42:23.000Z"><i class="far fa-calendar-alt">&nbsp;</i>2019-12-29</time>
                
                <time class="level-item has-text-grey is-hidden-mobile" datetime="2019-12-29T12:56:13.071Z"><i class="far fa-calendar-check">&nbsp;</i>2019-12-29</time>
                
                
                <div class="level-item">
                <i class="far fa-folder-open has-text-grey"></i>&nbsp;
                <a class="has-link-grey -link" href="/categories/blog-back-new/">blog_back_new</a>&nbsp;/&nbsp;<a class="has-link-grey -link" href="/categories/blog-back-new/django/">django</a>
                </div>
                
                
                <span class="level-item has-text-grey">
                    <i class="far fa-clock"></i>&nbsp;
                    
                    
                    15 minutes read (About 2186 words)
                </span>
                
                
                <span class="level-item has-text-grey" id="busuanzi_container_page_pv">
                    <i class="far fa-eye"></i>
                    <span id="busuanzi_value_page_pv">0</span> visits
                </span>
                
            </div>
        </div>
        
        <div class="content">
            <h2 id="rust风格"><a href="#rust风格" class="headerlink" title="rust风格"></a>rust风格</h2><p>Representational State Transfer  表现层状态转化（ 资源定位及资源操作）<br>表象层面说就是通过get,post,put,delete方式来实现前后台通信的一种轻量级,跨平台,跨语言架构设计风格的web服务</p>
<p>http不仅仅是传输协议，更是一种应用协议。REST，即Representational State Transfer的缩写。意为是”表现层状态转化”。RESTful表示一种风格，理解REST前需要理解资源，何谓资源，广义的资源是指可以操作的所有对象。可能是一个系统资源，如txt、jgp、xml …，亦可以是诸如自己定义的虚拟集合的抽象，如books、usrs、times。RESTfutl代表一种简洁、方便、快捷、高效、透明的架构，这取决于你怎样组合。具有如下特点：</p>
<p>1、规范化接口访问方式。这些http操作方法包括GET/POST/PUT/DELETE/OPTIONS等，每个操作方法都代表一个相同意义的操作，它向所有人透明地表明操作方式。比如GET只能读取/拉数据，当然你也可以是添加数据，但建议不要这么做，不然这样就失去了REST的意义。<br>GET 读取<br>POST 添加<br>PUT 修改<br>DELETE 删除<br>2、资源标识唯一。通过URI表示一个资源名称，形式/resource/patch。如/users，表示用户的组合，或用户群。当然还可以继续标识某个具体的一个用户，/users/11，表示id为11的用户。当然，你也可以又用一组/usrgroup/11的URI代表操作用户组，不过不建议这么做，因为这样从字面上重复了/users/11资源表示的内容。一个资源URI总是包含第一条实现的方法：<br>GET /users/11<br>POST /users/11<br>PUT /users/11<br>DELETE /users/11<br>当然，仅有这些还不足以包括资源操作的所有需求，所以还可以包含请求参数，如GET /users?type=list&amp;page=1。<br>3、状态的转化。这就是REST的真实含义，指它允许资源URI具有不同的表现形式。同一个URI，根据不同请求方式，执行的动作不同；还可以根据请求的Header Accept的不同返回不同的结果，如text/html、text/css、text/xml等等。也可以理解为body不同。如查询快递一般，可以上次查询，物品还在仓库，而过一段时间已经在路上了。它表示的是一个互动过程。<br>4、所有信息都包含在当前请求中。请求的方式包含在 Request Header的Method中，还可以包含Accept、Accept-Encoding、Accept-Language，使用Authentication、Cookie等信息表明身份。同样，服务端通过发送Content-Length、Content-Type响应执行情况。最重要的是，需要返回Status Code通知执行状态，如200 201 400 404 500等http code。REST认为，所有信息都能通过请求一次性发送，而不必再采用方式保存状态，请求的信息本身已经说明了请求的意义。<br>5、无状态性。这是REST最重要的特性之一，这个状态指的是客户端与服务端无需为每次保存请求状态，客户端请求不必考虑当前状态，不必考虑上下文。具体上说，就是不必使用session等工具跟踪、保存请求的特殊性。比如，无论是谁，从哪里发送，几时发送，对同一个URI资源发送请求的结果都是一样的。据传，这样的设计是为当一台服务器宕机时，另一台服务器可以无差别地响应对方的请求。客户端请求只认URI，而不需理后台的设计。<br>实际上，在如今执行的RESTful设计当中，完全能执行这个要求的很少，最彻底的云服务，大部份为RESTful-like的风格。<br>6、可实现请求缓存。通过缓存减少请求次数，在HTTP响应里利用Cache-Control、Expires、Last-Modified三个头字段，可以让浏览器缓存资源一段时间。</p>
<h2 id="drf的视图集"><a href="#drf的视图集" class="headerlink" title="drf的视图集"></a>drf的视图集</h2><p>ViewSet类只是一种类型的基于类的视图，即不提供任何方法的处理程序，例如.get()或.post()，而是提供操作，如.list()和.create()。<br><a href="http://www.sinodocs.cn/api-guide/viewsets.html" target="_blank" rel="noopener">http://www.sinodocs.cn/api-guide/viewsets.html</a></p>
<h3 id="drf字段更新"><a href="#drf字段更新" class="headerlink" title="drf字段更新"></a>drf字段更新</h3><p>默认只有list和create 对应的方法就是get 和post<br>partial = True 局部更新</p>
<pre><code class="python">class TestViewSet(viewsets.ModelViewSet):
    serializer_class = TestSerializer
    queryset = test_Model.objects.all()

 @action(methods=[&#39;patch&#39;], detail=False)
    def update_field(self, request, *args, **kwargs):
        request.data[&quot;text&quot;] = &quot;更新dsdsd&quot;
        instance = test_Model.objects.get(id=request.data[&#39;id&#39;])
        # instance = self.get_object() 会报错
        # https://docs.djangoproject.com/en/2.2/ref/class-based-views/mixins-single-object/#django.views.generic.detail.SingleObjectMixin.get_object
        # 默认使用id查找
        serializer = self.get_serializer(instance,data=request.data,partial=True)
        serializer.is_valid()
        serializer.save()
        return Response(serializer.data,status=status.HTTP_200_OK)

    @action(methods=[&#39;delete&#39;],detail=False)
    def delete_field(self,request,*args,**kwargs):
        instance = test_Model.objects.get(id=request.data[&#39;id&#39;])
        if instance:
            self.perform_destroy(instance)
            return Response({&quot;flag&quot;:&quot;删除成功&quot;},status=status.HTTP_200_OK)
        else:
            return  Response(status=status.HTTP_400_BAD_REQUEST)</code></pre>
<h3 id="基本的视图集"><a href="#基本的视图集" class="headerlink" title="基本的视图集"></a>基本的视图集</h3><p>使用viewsets.ModelViewSet + DefaultRouter<br>其中base-name表示基础url  lookup表示查询参数(只根据主键查找)<br>获取局部地址 <a href="http://localhost:8080/{base-name}/{lookup}" target="_blank" rel="noopener">http://localhost:8080/{base-name}/{lookup}</a></p>
<h2 id="drf路由集"><a href="#drf路由集" class="headerlink" title="drf路由集"></a>drf路由集</h2><p>为了更加便捷的开发项目,drf设计了路由集的内容，免去了路由配置中的麻烦，当然他也同时兼容django的路由设计<br><a href="https://www.django-rest-framework.org/api-guide/routers/" target="_blank" rel="noopener">https://www.django-rest-framework.org/api-guide/routers/</a></p>
<h3 id="使用"><a href="#使用" class="headerlink" title="使用"></a>使用</h3><pre><code class="python">from rest_framework import routers

router = DefaultRouter(trailing_slash=False) # 是否以斜杠/结尾
# 声明注册路由
# 同path(&#39;switch/&#39;,views.per_switch.as_view()),
router.register(prefix=&#39;users&#39;, viewset=UserViewSet,basename=&quot;another_name&quot;)
router.register(&#39;accounts&#39;, AccountViewSet)

# 添加规则，django主动扫描urlpatterns变量获取路由
urlpatterns = router.urls </code></pre>
<p>以上 </p>
<ul>
<li>prefix定义前缀</li>
<li>viewset定义视图</li>
<li>basename定义前缀别名</li>
</ul>
<p>形成url格式(本地) —&gt;<br><a href="http://localhost:8080/user/" target="_blank" rel="noopener">http://localhost:8080/user/</a><br><a href="http://localhost:8000/accounts/" target="_blank" rel="noopener">http://localhost:8000/accounts/</a></p>
<h3 id="兼容使用"><a href="#兼容使用" class="headerlink" title="兼容使用"></a>兼容使用</h3><pre><code class="python">framework rest_framework.routers import DefaultRouter

router = DefaultRouter()
router.register(&#39;test&#39;,viewset=TestViewSet,base_name=&quot;test&quot;)

urlpatterns = [
    path(&#39;switch/&#39;,views.switch_list.as_view()),
]

# 变量累加
urlpatterns += router.urls </code></pre>
<h3 id="路由集url"><a href="#路由集url" class="headerlink" title="路由集url"></a>路由集url</h3><p>django的路由集是真滴变态，当你使用带值参数去查找列表中的特定内容时候，他所表现的url是<br>^users/{pk}/set_password/$<br>注意 pk在中间 set_password是你方法的名字<br>如果你需要修改这些内容，可以在@action中指定<br>url_path = set_password<br>url_name = change_password</p>
<pre><code class="python">class SwitchViewSet(viewsets.GenericViewSet,
                    mixins.ListModelMixin):
    serializer_class = SwitchSerializer
    queryset = SwitchModel.objects.all()

    # get
    @action(detail=True,url_path=&quot;xx&quot;)
    def list_peer(self, request, pk):
        queryset = SwitchModel.objects.get(name=pk)
        print(queryset)
        # page = self.paginate_queryset(queryset)
        # if page is not None:
        #    serializer = self.get_serializer(page, many=True)
        #    return self.get_paginated_response(serializer.data)

        serializer = self.get_serializer(queryset)
        return Response(serializer.data) </code></pre>
<p>如上一个列表查询的地址是  <a href="http://localhost:8080/{pk}/xx" target="_blank" rel="noopener">http://localhost:8080/{pk}/xx</a></p>
<h2 id="drf过滤"><a href="#drf过滤" class="headerlink" title="drf过滤"></a>drf过滤</h2><h3 id="drf通用过滤"><a href="#drf通用过滤" class="headerlink" title="drf通用过滤"></a>drf通用过滤</h3><pre><code class="bash"># setting.py
# 全局设置过滤器
REST_FRAMEWORK = {
    &#39;DEFAULT_FILTER_BACKENDS&#39;: [&#39;django_filters.rest_framework.DjangoFilterBackend&#39;]
}
# views.py
# 单视图设置过滤器
  filter_backends = [django_filters.rest_framework.DjangoFilterBackend]</code></pre>
<p><a href="https://www.django-rest-framework.org/api-guide/filtering/" target="_blank" rel="noopener">https://www.django-rest-framework.org/api-guide/filtering/</a></p>
<h2 id="drf分页"><a href="#drf分页" class="headerlink" title="drf分页"></a>drf分页</h2><p><a href="https://www.django-rest-framework.org/api-guide/pagination/" target="_blank" rel="noopener">https://www.django-rest-framework.org/api-guide/pagination/</a></p>
<h2 id="drf过滤器"><a href="#drf过滤器" class="headerlink" title="drf过滤器"></a>drf过滤器</h2><p><a href="https://www.django-rest-framework.org/api-guide/serializers/" target="_blank" rel="noopener">https://www.django-rest-framework.org/api-guide/serializers/</a></p>
<h2 id="drf解析器与渲染器"><a href="#drf解析器与渲染器" class="headerlink" title="drf解析器与渲染器"></a>drf解析器与渲染器</h2><p>视图的有效解析器集始终定义为类列表。当 request.data被访问时，REST框架将检查Content-Type传入请求上的标头，并确定使用哪个解析器来解析请求内容。<br>如果您未设置内容类型，则大多数客户端将默认使用’application/x-www-form-urlencoded’例如，如果要json使用jQuery和.ajax（）方法发送编码数据，则应确保包括该contentType: ‘application/json’设置。</p>
<h3 id="设置解析器"><a href="#设置解析器" class="headerlink" title="设置解析器"></a>设置解析器</h3><p>仅允许json的内容</p>
<pre><code class="bash"># setting.py
# 全局设置解析
REST_FRAMEWORK = {
    &#39;DEFAULT_PARSER_CLASSES&#39;: [
        &#39;rest_framework.parsers.JSONParser&#39;,
    ]
} 
# 单视图设置解析
class modelview():
    parser_classes = [JSONParser]</code></pre>
<p>其他各类解析<br><a href="https://www.django-rest-framework.org/api-guide/parsers/" target="_blank" rel="noopener">https://www.django-rest-framework.org/api-guide/parsers/</a></p>
<h2 id="渲染器"><a href="#渲染器" class="headerlink" title="渲染器"></a>渲染器</h2><p>既然有收的解析器，那也有发出数据的渲染器，<br>REST框架包括许多内置的Renderer类，使您可以返回各种媒体类型的响应。还支持定义自己的自定义渲染器，这使您可以灵活地设计自己的媒体类型。</p>
<h3 id="设置渲染器"><a href="#设置渲染器" class="headerlink" title="设置渲染器"></a>设置渲染器</h3><pre><code class="bash"># setting.py
# 全局设置解析
REST_FRAMEWORK = {
    &#39;DEFAULT_RENDERER_CLASSES&#39;: [
        &#39;rest_framework.renderers.JSONRenderer&#39;,
        &#39;rest_framework.renderers.BrowsableAPIRenderer&#39;,
    ]
} 
# 单视图设置解析
class modelview()
    renderer_classes = [JSONRenderer]</code></pre>
<p>其他渲染器<br><a href="https://www.django-rest-framework.org/api-guide/renderers/" target="_blank" rel="noopener">https://www.django-rest-framework.org/api-guide/renderers/</a></p>

        </div>
        
            <ul class="post-copyright">
            <li><strong>本文标题：</strong><a href="http://alpaca-h.gitee.io/2019/12/29/blog_back_new/django/drf%E6%A1%86%E6%9E%B6/drf%E6%A1%86%E6%9E%B6/">DRF框架</a></li>
            <li><strong>本文作者：</strong><a href="http://alpaca-h.gitee.io">Alpaca</a></li>
            <li><strong>本文链接：</strong><a href="http://alpaca-h.gitee.io/2019/12/29/blog_back_new/django/drf%E6%A1%86%E6%9E%B6/drf%E6%A1%86%E6%9E%B6/">http://alpaca-h.gitee.io/2019/12/29/blog_back_new/django/drf%E6%A1%86%E6%9E%B6/drf%E6%A1%86%E6%9E%B6/</a></li>
            <li><strong>发布时间：</strong>2019-12-29</li>
            <li><strong>版权声明：</strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" rel="external nofollow" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明出处！
            </li>
            </ul>
        
        
        
        
    </div>
</div>





<div class="card card-transparent">
    <div class="level post-navigation is-flex-wrap is-mobile">
        
        <div class="level-start">
            <a class="level level-item has-link-grey  article-nav-prev" href="/2019/12/29/blog_back_new/django/django%E7%94%A8%E6%88%B7/">
                <i class="level-item fas fa-chevron-left"></i>
                <span class="level-item">django 用户</span>
            </a>
        </div>
        
        
        <div class="level-end">
            <a class="level level-item has-link-grey  article-nav-next" href="/2019/12/29/blog_back_new/django/django%E5%AD%97%E6%AE%B5%E6%80%BB%E7%BB%93/">
                <span class="level-item">django字段总结</span>
                <i class="level-item fas fa-chevron-right"></i>
            </a>
        </div>
        
    </div>
</div>



</div>
                




<div class="column is-4-tablet is-4-desktop is-3-widescreen  has-order-1 column-left ">
    
        
<div class="card widget">
    <div class="card-content">
        <nav class="level" style="margin-bottom:1rem">
            <div class="level-item has-text-centered">
                <div>
                    
                        <img class="image is-96x96 has-mb-6" src="https://www.gravatar.com/avatar/e0f4032c0f2d1068ffffbaf93c0bef52?s=96" alt="Xinyu Liu">
                    
                    
                    <p class="is-size-4 is-block">
                        Xinyu Liu
                    </p>
                    
                    
                    <p class="is-size-6 is-block">
                        Alpha Lxy
                    </p>
                    
                    
                    <p class="is-size-6 is-flex is-flex-center has-text-grey">
                        <i class="fas fa-map-marker-alt has-mr-7"></i>
                        <span>Beijing, China</span>
                    </p>
                    
                </div>
            </div>
        </nav>
        <nav class="level menu-list is-mobile" style="margin-bottom:1rem">
            <div class="level-item has-text-centered is-marginless">
                <a href="/archives/">
                    <p class="heading">
                        Posts
                    </p>
                    <p class="title has-text-weight-normal">
                        40
                    </p>
                </a>
            </div>
            <div class="level-item has-text-centered is-marginless">
                <a href="/categories/">
                    <p class="heading">
                        Categories
                    </p>
                    <p class="title has-text-weight-normal">
                        13
                    </p>
                </a>
            </div>
            <div class="level-item has-text-centered is-marginless">
                <a href="/tags/">
                    <p class="heading">
                        Tags
                    </p>
                    <p class="title has-text-weight-normal">
                        0
                    </p>
                </a>
            </div>
        </nav>
        <div class="level">
            <a class="level-item button is-link is-rounded" href="https://www.github.com/AlphaLxy" target="_blank">
                <i class="fab fa-github"></i>&nbsp;&nbsp;Follow</a>
        </div>
        
        
    </div>
</div>

    
        
<div class="card widget column-left is-sticky" id="toc">
    <div class="card-content">
        <div class="menu">
            <h3 class="menu-label">
                Catalogue
            </h3>
            <ul class="menu-list"><li>
        <a class="is-flex" href="#rust风格">
        <span class="has-mr-6">1</span>
        <span>rust风格</span>
        </a></li><li>
        <a class="is-flex" href="#drf的视图集">
        <span class="has-mr-6">2</span>
        <span>drf的视图集</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#drf字段更新">
        <span class="has-mr-6">2.1</span>
        <span>drf字段更新</span>
        </a></li><li>
        <a class="is-flex" href="#基本的视图集">
        <span class="has-mr-6">2.2</span>
        <span>基本的视图集</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#drf路由集">
        <span class="has-mr-6">3</span>
        <span>drf路由集</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#使用">
        <span class="has-mr-6">3.1</span>
        <span>使用</span>
        </a></li><li>
        <a class="is-flex" href="#兼容使用">
        <span class="has-mr-6">3.2</span>
        <span>兼容使用</span>
        </a></li><li>
        <a class="is-flex" href="#路由集url">
        <span class="has-mr-6">3.3</span>
        <span>路由集url</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#drf过滤">
        <span class="has-mr-6">4</span>
        <span>drf过滤</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#drf通用过滤">
        <span class="has-mr-6">4.1</span>
        <span>drf通用过滤</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#drf分页">
        <span class="has-mr-6">5</span>
        <span>drf分页</span>
        </a></li><li>
        <a class="is-flex" href="#drf过滤器">
        <span class="has-mr-6">6</span>
        <span>drf过滤器</span>
        </a></li><li>
        <a class="is-flex" href="#drf解析器与渲染器">
        <span class="has-mr-6">7</span>
        <span>drf解析器与渲染器</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#设置解析器">
        <span class="has-mr-6">7.1</span>
        <span>设置解析器</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#渲染器">
        <span class="has-mr-6">8</span>
        <span>渲染器</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#设置渲染器">
        <span class="has-mr-6">8.1</span>
        <span>设置渲染器</span>
        </a></li></ul></li></ul>
        </div>
    </div>
</div>


    
    
        <div class="column-right-shadow is-hidden-widescreen ">
        
        </div>
    
</div>

                
            </div>
        </div>
    </section>
    <footer class="footer">
    <div class="container">
        <div class="level">
            <div class="level-start has-text-centered-mobile">
                <a class="footer-logo is-block has-mb-6" href="/">
                
                    <img src="/images/logo.svg" alt="DRF框架" height="28">
                
                </a>
                <p class="is-size-7">
                &copy; 2020 Alpaca&nbsp;
                Powered by <a href="http://hexo.io/" target="_blank">Hexo</a> & <a
                        href="http://github.com/ppoffice/hexo-theme-icarus" target="_blank">Icarus</a>
                
                <br>
                <span id="busuanzi_container_site_uv">
                Visited by <span id="busuanzi_value_site_uv">0</span> users
                </span>
                
                </p>
            </div>
            <div class="level-end">
            
                <div class="field has-addons is-flex-center-mobile has-mt-5-mobile is-flex-wrap is-flex-middle">
                
                
                <p class="control">
                    <a class="button is-white is-large" target="_blank" title="CC BY-NC-SA 4.0" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
                        
                        <i class="fab fa-creative-commons"></i>&nbsp;<i class="fab fa-creative-commons-by"></i>&nbsp;<i class="fab fa-creative-commons-nc"></i>&nbsp;<i class="fab fa-creative-commons-sa"></i>&nbsp;
                        
                    </a>
                </p>
                
                <p class="control">
                    <a class="button is-white is-large" target="_blank" title="AlphaLxy GitHub" href="https://www.github.com/AlphaLxy">
                        
                        <i class="fab fa-github"></i>&nbsp;
                        
                    </a>
                </p>
                
                </div>
            
            </div>
        </div>
    </div>
</footer>

    <script src="https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/moment@2.22.2/min/moment-with-locales.min.js"></script>
<script>moment.locale("en");</script>


    
    
    
    <script src="/js/animation.js"></script>
    

    
    
    
    <script src="https://cdn.jsdelivr.net/npm/lightgallery@1.6.8/dist/js/lightgallery.min.js" defer></script>
    <script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js" defer></script>
    <script src="/js/gallery.js" defer></script>
    

    
    

<div id="outdated">
    <h6>Your browser is out-of-date!</h6>
    <p>Update your browser to view this website correctly. <a id="btnUpdateBrowser" href="http://outdatedbrowser.com/" target="_blank" rel="noopener">Update
            my browser now </a></p>
    <p class="last"><a href="#" id="btnCloseUpdateBrowser" title="Close">&times;</a></p>
</div>
<script src="https://cdn.jsdelivr.net/npm/outdatedbrowser@1.1.5/outdatedbrowser/outdatedbrowser.min.js" defer></script>
<script>
    document.addEventListener("DOMContentLoaded", function () {
        outdatedBrowser({
            bgColor: '#f25648',
            color: '#ffffff',
            lowerThan: 'flex'
        });
    });
</script>


    
    
<script src="https://cdn.jsdelivr.net/npm/mathjax@2.7.5/unpacked/MathJax.js?config=TeX-MML-AM_CHTML" defer></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
    MathJax.Hub.Config({
        'HTML-CSS': {
            matchFontHeight: false
        },
        SVG: {
            matchFontHeight: false
        },
        CommonHTML: {
            matchFontHeight: false
        },
        tex2jax: {
            inlineMath: [
                ['$','$'],
                ['\\(','\\)']
            ]
        }
    });
});
</script>

    
    

<a id="back-to-top" title="Back to Top" href="javascript:;">
    <i class="fas fa-chevron-up"></i>
</a>
<script src="/js/back-to-top.js" defer></script>


    
    

    
    
    
    

    
    
    
    
    
    <script src="https://cdn.jsdelivr.net/npm/clipboard@2.0.4/dist/clipboard.min.js" defer></script>
    <script src="/js/clipboard.js" defer></script>
    

    
    
    

    


<script src="/js/main.js" defer></script>

    
    <div class="searchbox ins-search">
    <div class="searchbox-container ins-search-container">
        <div class="searchbox-input-wrapper">
            <input type="text" class="searchbox-input ins-search-input" placeholder="Type something..." />
            <span class="searchbox-close ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
        </div>
        <div class="searchbox-result-wrapper ins-section-wrapper">
            <div class="ins-section-container"></div>
        </div>
    </div>
</div>
<script>
    (function (window) {
        var INSIGHT_CONFIG = {
            TRANSLATION: {
                POSTS: 'Posts',
                PAGES: 'Pages',
                CATEGORIES: 'Categories',
                TAGS: 'Tags',
                UNTITLED: '(Untitled)',
            },
            CONTENT_URL: '/content.json',
        };
        window.INSIGHT_CONFIG = INSIGHT_CONFIG;
    })(window);
</script>
<script src="/js/insight.js" defer></script>
<link rel="stylesheet" href="/css/search.css">
<link rel="stylesheet" href="/css/insight.css">
    
</body>
</html>